home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 9550 < prev    next >
Encoding:
Text File  |  1996-08-05  |  1.4 KB  |  51 lines

  1. Path: solon.com!not-for-mail
  2. From: seebs@solutions.solon.com (Peter Seebach)
  3. Newsgroups: comp.sources.wanted,comp.lang.c,comp.unix.programmer
  4. Subject: Re: Seek unix2dos.c OR help with tr
  5. Date: 10 Mar 1996 23:01:21 -0600
  6. Organization: Usenet Fact Police (Undercover)
  7. Message-ID: <4i0c31$r1g@solutions.solon.com>
  8. References: <4i0946$7io@nuke.csu.net>
  9. NNTP-Posting-Host: solutions.solon.com
  10.  
  11. In article <4i0946$7io@nuke.csu.net>,
  12. Emmett Mclean <mclean@futon.SFSU.EDU> wrote:
  13. >Ah, writing the program is a bit trickier
  14. >than the little program below since the
  15. >program exits prematurely because getchar reads
  16. >EOF from its input - before getting to
  17. >the real EOF.
  18.  
  19. >#include <stdio.h>
  20. >main(){
  21. >char c;
  22. >while(EOF!=(c=getchar())){
  23.  
  24.  
  25. ARGH!!!
  26.  
  27. How many times must this be said?
  28.  
  29. *getchar returns an int*.  *NEVER* try to shove the return of getchar into a
  30. char *before you check for EOF*.
  31.  
  32. Declare c as an int.
  33.  
  34. > if(10==c)putchar(13);
  35. > putchar(c);
  36. > }
  37. > putchar(10);
  38. >}
  39.  
  40. The last putchar(10) is wrong, but the guts of the code are probably
  41. correct.
  42.  
  43. Assuming this is not a binary file; if it is, don't touch it.
  44.  
  45. -s
  46. -- 
  47. Peter Seebach - seebs@solon.com - Copyright 1996 Peter Seebach.
  48. C/Unix wizard -- C/Unix questions? Send mail for help.  No, really!
  49. FUCK the communications decency act.  Goddamned government.  [literally.]
  50. The *other* C FAQ - http://www.solon.com/~seebs/c/c-iaq.html
  51.